$(document).ready(function() {	
	$("#frmRegister").validate({	
		errorClass		: 'errorMessage',
		errorElement	: 'span',
		onfocusout		: false,
		onkeyup			: false,
		rules: {
			pfirstname:{
				requiredName 		: true,
				minlengthName		: true
			},
			premail:{
				required 			: true,
				email				: true
			},
			prpassword:{
				required			: true,
				minlength			: 8
			},
			ppassword_confirm:{
				required			: true,
				equalTo				: '#prpassword'
			},
			pgender: {
				required			: true
			},
			pday: {
				birthdateRequired	: true,
				//validateBirthdate	: true
			},
			psrcid: {
				required			: true
			},
			pcaptcha: {
				required			: true,
				validateCaptcha		: true
			},
			ptos: {
				requiredCheck		: true
			}
		},
		messages: {
			pfirstname:{
				requiredName 		: fullname_required,
				minlengthName		: fullname_minlength
			},
			premail:{
				required 			: email_required,
				email				: email_invalid
			},
			prpassword:{
				required			: password_required,
				minlength			: password_minlength
			},
			ppassword_confirm:{
				required			: confirmpassword_required,
				equalTo				: confirmpassword_equalto
			},
			pgender: {
				required			: gender_required
			},
			pday: {
				birthdateRequired	: birthdate_required,
				//validateBirthdate	: birthdate_invalid
			},
			psrcid: {
				required			: src_required
			},
			pcaptcha: {
				required			: captcha_required,
				validateCaptcha		: captcha_invalid
			},
			ptos: {
				requiredCheck		: tos_required
			}
		},		
		errorPlacement: function(label, element) {
			var id = element.attr('id');	
			if(id == 'pfirstname') {
				label.insertAfter($('#plastname'));			
			}else if(id == 'pgender') {
				label.insertAfter($('.gender'));
			}else if(id == 'pday') {
				label.insertAfter($('.year'));
			}else if(id == 'ptos') {
				label.insertBefore($('.tos'));
			}else {
				label.insertAfter($('#' + id));			
			}
		}	
	});	
	$.validator.addMethod('requiredName',function(){
		strFirstName = $('#pfirstname').val();
		strLastName	 = $('#plastname').val();
		if(strFirstName == "" || strLastName == "") {
			return false;
		}
		return true;
	});
	$.validator.addMethod('minlengthName',function(){
		strFirstName = $('#pfirstname').val();
		strLastName	 = $('#plastname').val();
		if((strFirstName != "" && strFirstName.length < 2) || (strLastName != "" && strLastName.length < 2)) {
			return false;
		}
		return true;
	});
	$.validator.addMethod('validateCaptcha', function() {
		var strCaptchaInput = $('#pcaptcha').val();
		return validateCaptcha(strCaptchaInput);
	});
	$.validator.addMethod('requiredCheck',function(){
		if(!$('#ptos').is(':checked')) {
			return false;
		}
		return true;
	});
	$.validator.addMethod('birthdateRequired', function(){		
		var year 	= $('#pyear').val();
		var month 	= $('#pmonth').val();
		var day 	= $('#pday').val();		
		if (year == "" || month == "" || day == "")
			return false;
		return true;
	});
	$.validator.addMethod('validateBirthdate', function(){											
		var year 	= $('#pyear').val();
		var month 	= $('#pmonth').val();
		var day 	= $('#pday').val();
		return checkDate(year,month,day);												
	});
});
